﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebServices
{
    public class DoEvents
    {
        public delegate void DoEventHandler(object sender, HandleDataArg e);

        public event DoEventHandler CurEvent;

        protected virtual void OnDoEvent(HandleDataArg e)
        {
            if (CurEvent != null)
            {
                CurEvent(this, e);
            }
        }

        //引发事件
        public void RaiseEvent(DataContainer data)
        {
            HandleDataArg e = new HandleDataArg(data);
            OnDoEvent(e);
        }
    }

    public class HandleDataArg : EventArgs
    {
        public readonly DataContainer data;
        public HandleDataArg(DataContainer Data)
        {
            data = Data;
        }
    }

    public class DataContainer
    {
        public int ID { get; set; }
        public string name { get; set; }
        public DateTime dt { get; set; }
    }

    //监听事件
    public class DataMonitor
    {
        public void SendDataToNet(object sender, HandleDataArg e)
        {
            //发送给联网公司

        }

        public void Subscribe(DoEvents doEvent)
        {
            doEvent.CurEvent += new DoEvents.DoEventHandler(SendDataToNet);
        }

        public void UnSubscribe(DoEvents doEvent)
        {
            doEvent.CurEvent -= new DoEvents.DoEventHandler(SendDataToNet);
        }
    }
}